package io.jsen.meta.diff.obj.abs;

import io.jsen.meta.diff.field.MetaField;
import io.jsen.meta.diff.obj.MetaObject;

import static io.jsen.meta.diff.support.MetaChangeModifier.*;

/**
 * @author jsen
 * @date 2021/05/01
 **/
public abstract class AbstractComparable<O extends AbstractComparable<O, S>, S extends Comparable<? super S>>
        extends MetaObject<O, S> {
    protected AbstractComparable(MetaField field, S val) {
        super(field, val);
    }

    @Override
    protected int calState(O obj) {
        if (isDelVal()) {
            return setDelete(0);
        }
        return val.compareTo(obj.val) == 0 ? setNoChange(0) : setChange(0);
    }


    @Override
    public String createIndex() {
        return val.toString();
    }
}
